package balmysundaycandy.more.low.level.taskqueue;

import com.google.appengine.api.labs.taskqueue.TaskQueuePb.TaskQueueAddRequest;
import com.google.appengine.api.labs.taskqueue.TaskQueuePb.TaskQueueAddResponse;
import com.google.appengine.api.labs.taskqueue.TaskQueuePb.TaskQueueDeleteQueueRequest;
import com.google.appengine.api.labs.taskqueue.TaskQueuePb.TaskQueueDeleteQueueResponse;
import com.google.appengine.api.labs.taskqueue.TaskQueuePb.TaskQueueDeleteRequest;
import com.google.appengine.api.labs.taskqueue.TaskQueuePb.TaskQueueDeleteResponse;
import com.google.appengine.api.labs.taskqueue.TaskQueuePb.TaskQueueFetchQueueStatsRequest;
import com.google.appengine.api.labs.taskqueue.TaskQueuePb.TaskQueueFetchQueueStatsResponse;
import com.google.appengine.api.labs.taskqueue.TaskQueuePb.TaskQueueFetchQueuesRequest;
import com.google.appengine.api.labs.taskqueue.TaskQueuePb.TaskQueueFetchQueuesResponse;
import com.google.appengine.api.labs.taskqueue.TaskQueuePb.TaskQueueQueryTasksRequest;
import com.google.appengine.api.labs.taskqueue.TaskQueuePb.TaskQueueQueryTasksResponse;
import com.google.appengine.api.labs.taskqueue.TaskQueuePb.TaskQueueUpdateQueueRequest;
import com.google.appengine.api.labs.taskqueue.TaskQueuePb.TaskQueueUpdateQueueResponse;
import com.google.appengine.repackaged.com.google.io.protocol.ProtocolMessage;
import com.google.apphosting.api.ApiProxy;

/**
 * taskqueue operation definition
 * 
 * @author marblejenka
 * 
 * @param <Request>
 *            request protocol buffer
 * @param <Response>
 *            response protocol buffer
 */
public abstract class TaskqueueOperation<Request extends ProtocolMessage<?>, Response extends ProtocolMessage<?>> {
	private static final String packageName = "taskqueue";

	public abstract Response call(Request request);

	public static final class AddOperation extends TaskqueueOperation<TaskQueueAddRequest, TaskQueueAddResponse> {
		@Override
		public TaskQueueAddResponse call(TaskQueueAddRequest request) {
			TaskQueueAddResponse response = new TaskQueueAddResponse();
			response.mergeFrom(ApiProxy.makeSyncCall(packageName, "Add", request.toByteArray()));
			return response;
		}
	}

	public static final class DeleteOperation extends TaskqueueOperation<TaskQueueDeleteRequest, TaskQueueDeleteResponse> {
		@Override
		public TaskQueueDeleteResponse call(TaskQueueDeleteRequest request) {
			TaskQueueDeleteResponse response = new TaskQueueDeleteResponse();
			response.mergeFrom(ApiProxy.makeSyncCall(packageName, "Delete", request.toByteArray()));
			return response;
		}
	}

	public static final class UpdateOperation extends TaskqueueOperation<TaskQueueUpdateQueueRequest, TaskQueueUpdateQueueResponse> {
		@Override
		public TaskQueueUpdateQueueResponse call(TaskQueueUpdateQueueRequest request) {
			TaskQueueUpdateQueueResponse response = new TaskQueueUpdateQueueResponse();
			response.mergeFrom(ApiProxy.makeSyncCall(packageName, "UpdateQueue", request.toByteArray()));
			return response;
		}
	}

	public static final class FetchQueuesOperation extends TaskqueueOperation<TaskQueueFetchQueuesRequest, TaskQueueFetchQueuesResponse> {
		@Override
		public TaskQueueFetchQueuesResponse call(TaskQueueFetchQueuesRequest request) {
			TaskQueueFetchQueuesResponse response = new TaskQueueFetchQueuesResponse();
			response.mergeFrom(ApiProxy.makeSyncCall(packageName, "FetchQueues", request.toByteArray()));
			return response;
		}
	}

	public static final class FetchQueueStatsOperation extends TaskqueueOperation<TaskQueueFetchQueueStatsRequest, TaskQueueFetchQueueStatsResponse> {
		@Override
		public TaskQueueFetchQueueStatsResponse call(TaskQueueFetchQueueStatsRequest request) {
			TaskQueueFetchQueueStatsResponse response = new TaskQueueFetchQueueStatsResponse();
			response.mergeFrom(ApiProxy.makeSyncCall(packageName, "FetchQueueStats", request.toByteArray()));
			return response;
		}
	}

	public static final class DeleteQueueOperation extends TaskqueueOperation<TaskQueueDeleteQueueRequest, TaskQueueDeleteQueueResponse> {
		@Override
		public TaskQueueDeleteQueueResponse call(TaskQueueDeleteQueueRequest request) {
			TaskQueueDeleteQueueResponse response = new TaskQueueDeleteQueueResponse();
			response.mergeFrom(ApiProxy.makeSyncCall(packageName, "DeleteQueue", request.toByteArray()));
			return response;
		}
	}

	public static final class QueryTasksOperation extends TaskqueueOperation<TaskQueueQueryTasksRequest, TaskQueueQueryTasksResponse> {
		@Override
		public TaskQueueQueryTasksResponse call(TaskQueueQueryTasksRequest request) {
			TaskQueueQueryTasksResponse response = new TaskQueueQueryTasksResponse();
			response.mergeFrom(ApiProxy.makeSyncCall(packageName, "QueryTasks", request.toByteArray()));
			return response;
		}
	}
}
